package com.example.sys.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.sys.entity.Menus;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author 罗文斌
 * @Date 2023/7/20
 * @Version 1.0.0
 */
@Mapper
public interface MenuMapper extends BaseMapper<Menus> {

    @Select("select a.id, a.label, a.name, a.path, a.icon, a.component, a.parent, a.sort " +
            "from sys_menu a")
    List<Menus> getMenu();

    @Select("select a.id, a.label, a.name, a.path, a.icon, a.component, a.parent, a.sort " +
            "from sys_menu a, sys_role_menu b " +
            "where a.id = b.menu_id and a.disabled = 0 and b.role = #{role}")
    List<Menus> getMenuByRole(String role);

    @Delete("delete from sys_role_menu where menu_id in (select id from sys_menu where parent = #{id} or id = #{id})")
    int removeRoleMenu(Integer id);

    @Update("update sys_menu set parent = 0 where parent = #{id}")
    int changeParent(Integer id);
}
